import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)

const request = Vue.axios.create({
    baseURL: 'http://localhost:8084',
    timeout: 30000
})

request.interceptors.request.use(request => {
    return request
}, error => {
    return Promise.reject(error)
})

request.interceptors.request.use(response => {
    return response
}, error => {
    return Promise.reject(error)
})

const requsetHanlder = (request, flag) => {
    return new Promise((resolve, reject) => {
        request.then(res => {
            resolve(res)
            return
        }).catch(err => {
            reject(err)
        })
    })
}

export default {
    request,
    requestHandler
}